package com.fpmsa.officeweb.config.web;

import com.fpmsa.officeweb.config.properties.OfficewebProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * web 配置类
 *
 * @author fengshuonan
 * @date 2016年11月12日 下午5:03:32
 */
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

    @Autowired
    private OfficewebProperties officewebProperties;

    /**
     * 增加swagger的支持
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        if (officewebProperties.getSwaggerOpen()) {
            registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
            registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
            // 增加文章附带图片的上传地址映射
            //registry.addResourceHandler("/files/**").addResourceLocations("file:///E:/files/newsImgs/");
            // 增加百度编辑器ueditor上传图片地址映射
            //registry.addResourceHandler("/ueditor/uploadImgs/**").addResourceLocations("file:///E:/ueditor/uploadImgs/**");

            // 线下
            //registry.addResourceHandler("/MP_verify_sfpa0ES1106ZRXnp.txt").addResourceLocations("file:///D:/fpmsaProject/files/MP_verify_sfpa0ES1106ZRXnp.txt");
            //registry.addResourceHandler("/baidu-verify-E7A2AFD82C.txt").addResourceLocations("file:///D:/fpmsaProject/files/baidu-verify-E7A2AFD82C.txt");
            //registry.addResourceHandler("/farvirate.ico").addResourceLocations("file:///D:/fpmsaProject/files/farvirate.ico");
            //registry.addResourceHandler("/files/**").addResourceLocations("file:///D:/fpmsaProject/files/");
            //registry.addResourceHandler("/ueditor/uploadImgs/**").addResourceLocations("file:///D:/fpmsaProject/ueditor/uploadImgs/");

            // 线上
            //registry.addResourceHandler("/files/newsImgs/**").addResourceLocations("file:///fpmsaProject/files/newsImgs/");
            // 微信相关文件
            registry.addResourceHandler("/MP_verify_sfpa0ES1106ZRXnp.txt").addResourceLocations("file:///fpmsaProject/files/MP_verify_sfpa0ES1106ZRXnp.txt");
            registry.addResourceHandler("/baidu-verify-E7A2AFD82C.txt").addResourceLocations("file:///fpmsaProject/files/baidu-verify-E7A2AFD82C.txt");
            registry.addResourceHandler("/farvirate.ico").addResourceLocations("file:///fpmsaProject/files/farvirate.ico");
            registry.addResourceHandler("/files/**").addResourceLocations("file:///fpmsaProject/files/");
            registry.addResourceHandler("/ueditor/uploadImgs/**").addResourceLocations("file:///fpmsaProject/ueditor/uploadImgs/");
        }
    }
}
